package com.sv.dao;

import com.sv.model.SdContentChannelCriteria;
import com.sv.model.SdContentChannel;
import com.sv.utils.SqlMapClientFactory;

import java.sql.SQLException;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Repository;

@Repository
@Configurable(autowire = Autowire.BY_TYPE)
public class SdContentChannelDAOImpl implements SdContentChannelDAO {

    // @Autowired
    // @Qualifier("sqlMapClient")
    // private SqlMapClient sqlMapClient;

    public int countByExample(SdContentChannelCriteria example)
            throws SQLException {
        Integer count = (Integer) SqlMapClientFactory.getSqlMapClient()
                .queryForObject(
                        "sd_content_channel.ibatorgenerated_countByExample",
                        example);
        return count.intValue();
    }

    public int deleteByExample(SdContentChannelCriteria example)
            throws SQLException {
        int rows = SqlMapClientFactory.getSqlMapClient().delete(
                "sd_content_channel.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    public int deleteByPrimaryKey(SdContentChannel key) throws SQLException {
        int rows = SqlMapClientFactory.getSqlMapClient().delete(
                "sd_content_channel.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    public void insert(SdContentChannel record) throws SQLException {
        SqlMapClientFactory.getSqlMapClient().insert(
                "sd_content_channel.ibatorgenerated_insert", record);
    }

    public void insertSelective(SdContentChannel record) throws SQLException {
        SqlMapClientFactory.getSqlMapClient().insert(
                "sd_content_channel.ibatorgenerated_insertSelective", record);
    }

    public List selectByExample(SdContentChannelCriteria example)
            throws SQLException {
        List list = SqlMapClientFactory.getSqlMapClient().queryForList(
                "sd_content_channel.ibatorgenerated_selectByExample", example);
        return list;
    }

    public int updateByExampleSelective(SdContentChannel record,
            SdContentChannelCriteria example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = SqlMapClientFactory.getSqlMapClient().update(
                "sd_content_channel.ibatorgenerated_updateByExampleSelective",
                parms);
        return rows;
    }

    public int updateByExample(SdContentChannel record,
            SdContentChannelCriteria example) throws SQLException {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = SqlMapClientFactory.getSqlMapClient().update(
                "sd_content_channel.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    private static class UpdateByExampleParms extends SdContentChannelCriteria {
        private Object record;

        public UpdateByExampleParms(Object record,
                SdContentChannelCriteria example) {
            super(example);
            this.record = record;
        }

        public Object getRecord() {
            return record;
        }
    }

    // public SqlMapClient getSqlMapClient() {
    // return sqlMapClient;
    // }
    //
    // public void setSqlMapClient(SqlMapClient sqlMapClient) {
    // this.sqlMapClient = sqlMapClient;
    // }

}
